package com.sibco.client.statistics;

import com.bstek.dorado.common.*;
import com.bstek.dorado.data.*;
import com.bstek.dorado.data.db.DBStatement;
import com.bstek.dorado.data.db.SqlDataset;
import com.bstek.dorado.utils.variant.VariantSet;
import com.bstek.dorado.view.*;
import com.bstek.dorado.view.data.*;
import com.bstek.dorado.view.control.*;
import com.sibco.client.system.User;
import java.util.*;

/**
 * SocialAccViewModel
 */
public class SocialAccViewModel extends DefaultViewModel {
  private List list=null;
  protected void doLoadData(ViewDataset dataset) throws Exception {
    // Add your code here
	
    super.doLoadData(dataset);
    
    if (dataset.getId().equals("datasetSocialAcc")){
       DoradoContext context = DoradoContext.getContext();
  	   User user = (User) context.getAttribute(context.SESSION, "User");
  	   String sql="";  	  
	   sql="select grp.group_type,grp.social_security_group_id,grp.group_name,count(*) emp_count from clt_ss ss,clt_cs_employee_on_off_post eoop,clt_ss_group grp "
		  +"where ss.employee_on_off_id=eoop.employee_on_off_id and eoop.company_id='"+user.getCompanyId()+"' "
		  +"and ss.social_security_group_id=grp.social_security_group_id and ss.status=3 "
		  +"group by grp.group_type,grp.social_security_group_id,grp.group_name";
	   DBStatement state=new DBStatement(); 	
	   state.setSql(sql);
	   list=state.queryForList();
	   state.close();

    }
    if (dataset.getId().equals("datasetSocial")){
    	for (int i=0;i<list.size();i++){
    		VariantSet var=(VariantSet)list.get(i);
    		if (var.getString("GROUP_TYPE").equals("1")){
    			dataset.insertRecord();
    			dataset.setValue("SOCIAL_SECURITY_GROUP_ID", var.getValue("SOCIAL_SECURITY_GROUP_ID"));
    			dataset.setValue("GROUP_NAME", var.getValue("GROUP_NAME"));
    			dataset.setValue("EMP_COUNT", var.getValue("EMP_COUNT"));
    		}
    	}    	
    }
    if (dataset.getId().equals("datasetAcc")){
    	for (int i=0;i<list.size();i++){
    		VariantSet var=(VariantSet)list.get(i);
    		if (var.getString("GROUP_TYPE").equals("2")){
    			dataset.insertRecord();
    			dataset.setValue("SOCIAL_SECURITY_GROUP_ID", var.getValue("SOCIAL_SECURITY_GROUP_ID"));
    			dataset.setValue("GROUP_NAME", var.getValue("GROUP_NAME"));
    			dataset.setValue("EMP_COUNT", var.getValue("EMP_COUNT"));
    		}
    	}    	
    }
  }

}
